package org.example.day20240909.view;

import org.example.day20240909.dao.DepartmentDao;
import org.example.day20240909.model.Department;
import org.example.day20240909.model.Employee;

import java.util.List;

public class DepartmentView {

    public void display(Department department){
        System.out.println("部门编号：" + department.getDepartment_id());
        System.out.println("部门名称：" + department.getDepartment_name());
        System.out.println("部门编制：" + department.getDepartment_quota());
        System.out.println("创建日期：" + department.getEstablishment_date());
        System.out.println("部长：" + department.getDepartment_head_name());
        System.out.println("上级部门：" + department.getSuperior_department_name());
        System.out.println("部门人数：" + department.getEmployee_num());
    }
    public boolean checkDepartmentId(String inputDepartmentId) {
        DepartmentDao departmentDao = new DepartmentDao();
        return departmentDao.findEmployeeDepartment(inputDepartmentId) != null;
    }

    public Department findEmployeeDepartment(String inputDepartment) {
        DepartmentDao departmentDao = new DepartmentDao();
        return departmentDao.findEmployeeDepartment(inputDepartment);
    }

    public void displayEmployeeDepartment(String inputDepartment) {
        DepartmentDao departmentDao = new DepartmentDao();
        Department department = departmentDao.findEmployeeDepartment(inputDepartment);
        display(department);
    }

    public void addDepartment(Department department) {
        DepartmentDao departmentDao = new DepartmentDao();
        departmentDao.addDepartment(department);
    }

    public void updateDepartment(Department department) {
        DepartmentDao departmentDao = new DepartmentDao();
        departmentDao.updateDepartment(department);
    }

    public void updateSameNameDepartment(Department department) {
        DepartmentDao departmentDao = new DepartmentDao();
        departmentDao.updateSameNameDepartment(department);
    }

    public void deleteDepartment(String inputId) {
        DepartmentDao departmentDao = new DepartmentDao();
        departmentDao.deleteDepartment(inputId);
    }

    public void displayDepartmentEmployee(String departmentId) {
        DepartmentDao departmentDao = new DepartmentDao();
        List<Employee> employeeList = departmentDao.displayDepartmentEmployee(departmentId);
        System.out.println("员工编号" + "\t\t\t" + "姓名" + "\t\t" + "性别"
                + "\t\t" + "生日" + "\t\t\t" + "入司日期" + "\t\t" + "当前部门" + "\t" + "状态");
        for (Employee employee : employeeList) {
            System.out.print(employee.getEmployee_id() + "\t");
            System.out.print(employee.getEmployee_name() + "\t\t");
            System.out.print(employee.getGender() + "\t\t");
            System.out.print(employee.getBirthday() + "\t");
            System.out.print(employee.getHire_date() + "\t");
            System.out.print(employee.getDepartment_name() + "\t\t");
            System.out.print(employee.getState() + "\n");
        }
    }

    public void displayDepartment(String inputId) {
        DepartmentDao departmentDao = new DepartmentDao();
        Department department = departmentDao.findEmployeeDepartment(inputId);
        display(department);
    }

    public void displayAllDepartment() {
        DepartmentDao departmentDao = new DepartmentDao();
        List<Department> departmentList = departmentDao.findAllDepartment();
        System.out.println("部门编号" + "\t" + "名称" + "\t\t" + "编制" + "\t\t\t"
                + "创建日期" + "\t\t" + "部长" + "\t\t" + "上级部门" + "\t" + "状态");
        for (Department department : departmentList) {
            System.out.print(department.getDepartment_id() + "\t\t");
            System.out.print(department.getDepartment_name() + "\t\t");
            System.out.print(department.getDepartment_quota() + "\t\t");
            System.out.print(department.getEstablishment_date() + "\t");
            System.out.print(department.getDepartment_head_name() + "\t\t");
            System.out.print(department.getSuperior_department_name() + "\t\t");
            System.out.print(department.getState() + "\n");
        }
    }
}
